export const getColor = () => {
  const oColor: Record<string, string> = {};
  for (let i = 0; i < document.styleSheets.length - 1; i++) {
    const styleSheet = document.styleSheets[i];
    if (styleSheet.href) {
      const cssRules = styleSheet.cssRules || styleSheet.rules;
      for (let j = 0; j < cssRules.length; j++) {
        const rule = cssRules[j] as CSSStyleRule;
        if (rule.type === CSSRule.STYLE_RULE && rule.selectorText.startsWith(':root')) {
          rule.cssText
            .replace(/:root {|}|\s/g, '')
            .split(';')
            .forEach(sItem => {
              const arr = sItem.split(':');
              if (arr.length == 2 && !arr[1].includes('var') && (arr[1].startsWith('#') || arr[1].startsWith('rgb'))) {
                oColor[arr[0]] = arr[1];
              }
            });
        }
      }
    }
  }
  return oColor;
};
